import {DynamicTable} from "./index.vue.d";
import {Column} from "vxe-table/types/column";
import {Table} from "vxe-table/types/table";
import {ColumnEditRule} from "vxe-table/types/validator";
import {CreateElement} from "vue/types/vue";
import {VNode} from "vue";
import {ColumnEditSlotParams} from "vxe-table/types/edit";
import {ColumnContentSlotParams, ColumnDefaultSlotParams} from "vxe-table/types/v-x-e-table";
import {ColumnHeaderSlotParams} from "vxe-table/types/header";
import {ColumnFooterSlotParams} from "vxe-table/types/footer";
import {ColumnFilterSlotParams} from "vxe-table/types/filter";
import {
  columnCheckboxSlotParams,
  columnRadioSlotParams, MyColumnCellRenderOptions,
  MyColumnEditRenderOptions,
  MyColumnFormatterMethodParams
} from "./vxe-table-plugin-element/MyTables";

// @ts-ignore
export class TableConfig implements Table {
  tableItems: TableItemConfig[] = []
  events: { [find: string]: Function } = {} // 记录事件
  /**
   *
   * @param self
   * @param items
   */
  constructor(self: DynamicTable, items: TableItemConfig[]) {
    Object.keys(self).forEach(key => {
      this[key] = self[key]
    })
    this.tableItems = items
  }
}

export interface ItemTypeSlots {
  default?: (props: ColumnDefaultSlotParams) => VNode[];
  header?: (props: ColumnHeaderSlotParams) => VNode[];
  footer?: (props: ColumnFooterSlotParams) => VNode[];
  title?: (props: ColumnDefaultSlotParams) => VNode[];
  checkbox?: (props: columnCheckboxSlotParams) => VNode[];
  radio?: (props: columnRadioSlotParams) => VNode[];
  content?: (props: ColumnContentSlotParams) => VNode[];
  filter?: (props: ColumnFilterSlotParams) => VNode[];
  edit?: (props: ColumnEditSlotParams) => VNode[];

  [key: string]: any;
}

// @ts-ignore
export interface TableItemConfig extends Column {
  children?: TableItemConfig[]; // 子项
  slotName?: string;
  label?: string;
  prop: string;
  checkboxUseElementUI?:boolean; // 默认true
  hidden?: boolean;
  setHidden?(tableData:any[],item:TableItemConfig):boolean;
  editRules?: ColumnEditRule[];

  formatter?: ((params: MyColumnFormatterMethodParams) => string) | any[] | string;

  typeSlots?(h: CreateElement, item: TableItemConfig): ItemTypeSlots;

  editRender: MyColumnEditRenderOptions;

  cellRender: MyColumnCellRenderOptions;
}
